package com.duniptech.soa.service;

import javax.activation.DataHandler;

import org.apache.axiom.attachments.ByteArrayDataSource;

import com.duniptech.soa.stub.upload.UploadStub;

public class UploadService implements UploadServiceInterface {
	
	protected UploadStub service;
	
	public UploadService(String endPoint) throws Exception {
		service = new UploadStub(endPoint);
	}
	
	public String upload(String serverPackage, byte[] arrayOfFileContents, byte[] arrayOfFileNames) throws Exception {
		UploadStub.Upload uploadArgs = new UploadStub.Upload();
		uploadArgs.setServerPackage(serverPackage);
		
		ByteArrayDataSource ds1 = new ByteArrayDataSource(arrayOfFileContents); 
		DataHandler dh1 = new DataHandler(ds1);     
		uploadArgs.setArrayOfFileContents(dh1);
		
		ByteArrayDataSource ds2 = new ByteArrayDataSource(arrayOfFileNames); 
		DataHandler dh2 = new DataHandler(ds2);
		uploadArgs.setArrayOfFileNames(dh2);
		
		return service.upload(uploadArgs).get_return();

	}
}
